import {NavBar} from "antd-mobile";
import PropTypes from "prop-types";
import { useNavigate , useLocation , useSearchParams} from "react-router-dom";

const NavbarAgain = (props) => {
    let navigate = useNavigate(),
        location = useLocation(),
        params = useSearchParams()[0]
    let { title } = props

    const  back = () => {
        // 返回按钮做特殊处理 ： 登录页 & to的值是/deatil/XXX
        let to = params.get('to')
        if(location.pathname === '/login' && /^\/detail\/\d+$/.test(to)){
           return navigate( to , {replace : true})
        }
        navigate(-1)
    }




    return <>
        <NavBar  onBack={back}>
            {title}
        </NavBar>
    </>

};



// 设置传参
NavbarAgain.defaultProps = {
    title:'个人中心'
}
NavbarAgain.propTypes = {
    title:PropTypes.string
}
export default NavbarAgain
